using BBX.Common;
using BBX.Entity;
using BBX.Forum;

namespace BBX.Web.UI
{
    public class UserCpPage : PageBase
    {
        public System.Int32 pageid = DNTRequest.GetInt("page", 1);
        public System.Int32 pagecount;
        public System.String pagenumbers = "";
        public IUser user;
        //public int announcepmcount = PrivateMessages.GetAnnouncePrivateMessageCount();
        public System.Int32 announcepmcount = ShortMessage.GetAnnouncePrivateMessageCount();
        public System.Int32 newnoticecount;
        public System.Int32 pmcount;
        public System.String[] score = Scoresets.GetValidScoreName();
        public System.Int32 maxmsg;
        public System.Int32 usedmsgcount;
        public System.Int32 usedmsgbarwidth;
        public System.Int32 unusedmsgbarwidth;

        protected System.Boolean IsLogin()
        {
            if (userid == -1)
            {
                base.AddErrLine("你尚未登录");
                return false;
            }
            user = Users.GetUserInfo(userid);
            if (user == null)
            {
                base.AddErrLine("用户不存在");
                return false;
            }
            return true;
        }

        protected void BindItems(System.Int32 recordCount, System.String pageName)
        {
            user = Users.GetUserInfo(userid);
            pagecount = ((recordCount % 16 == 0) ? (recordCount / 16) : (recordCount / 16 + 1));
            pagecount = ((pagecount == 0) ? 1 : pagecount);
            pageid = ((pageid < 1) ? 1 : pageid);
            pageid = ((pageid > pagecount) ? pagecount : pageid);
            pagenumbers = Utils.GetPageNumbers(pageid, pagecount, pageName, 8);
        }

        protected void BindItems(System.Int32 recordCount)
        {
            BindItems(recordCount, pagename.ToLower());
        }

        protected void BindPrivateMessage(System.Int32 folder)
        {
            pmcount = ShortMessage.GetPrivateMessageCount(userid, folder);
            usedmsgcount = ShortMessage.GetPrivateMessageCount(userid, folder);
            maxmsg = usergroupinfo.MaxPmNum;
            if (maxmsg > 0)
            {
                usedmsgbarwidth = usedmsgcount * 100 / maxmsg;
                unusedmsgbarwidth = 100 - usedmsgbarwidth;
            }
            BindItems(pmcount);
        }
    }
}